﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Sale.Report
{
    public partial class 油管结算清单 : System.Web.UI.Page
    {
        protected string year;
        protected string month;
        protected string RiQiStart;
        protected string RiQiEnd;
        protected string RiQi;


        /// <summary>
        /// 读入所有的SESSION数据，向VIEW暴露数据项
        /// </summary>
        protected void read_session()
        {
            year = DList_year.SelectedValue;
            month = DList_month.SelectedValue;
        }

        private string sql = @"
SELECT 
    dbo.产品出库单.日期, dbo.产品订货单位.名称, 
    dbo.产品.品名, dbo.产品.钢级, dbo.产品出库单.总件数, dbo.产品出库单.总支数, 
    dbo.产品出库单.总重量, dbo.产品出库单.总长度, COUNT(*) AS 车数
FROM  dbo.产品出库单 INNER JOIN
      dbo.产品销售合同 ON dbo.产品销售合同.ID = dbo.产品出库单.合同ID INNER JOIN
      dbo.产品订货单位 ON dbo.产品销售合同.订货单位ID = dbo.产品订货单位.ID INNER JOIN
      dbo.产品 ON dbo.产品出库单.产品类别ID = dbo.产品.ID
WHERE
    YEAR(dbo.产品出库单.日期)=*年份* AND
    MONTH(dbo.产品出库单.日期)=*月份*
GROUP BY 
    dbo.产品出库单.日期, 
    dbo.产品订货单位.名称, 
    dbo.产品.品名, dbo.产品.钢级, 
    dbo.产品出库单.总件数, dbo.产品出库单.总支数, 
    dbo.产品出库单.总重量, 
    dbo.产品出库单.总长度
HAVING (dbo.产品.品名 = N'油管')
ORDER BY dbo.产品出库单.日期";
        protected static DateTime date;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Message.Text = "·准备就绪";     
            
            if (!this.IsPostBack)
            {
                DList_year.SelectedValue = DateTime.Now.Year.ToString();
                DList_month.SelectedValue = DateTime.Now.Month.ToString();
                sql = sql.Replace("*年份*", DList_year.SelectedValue);
                sql = sql.Replace("*月份*", DList_month.SelectedValue);
                this.SqlDataSource1.SelectCommand = sql;
                this.ViewState["SelectCommand"] = sql;
            }
            read_session();
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        protected void DList_year_SelectedIndexChanged(object sender, EventArgs e)
        {
                sql = sql.Replace("*年份*", DList_year.SelectedValue);
                sql = sql.Replace("*月份*", DList_month.SelectedValue);
                this.SqlDataSource1.SelectCommand = sql;
                this.ViewState["SelectCommand"] = sql;
                this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        protected void DList_month_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("*年份*", DList_year.SelectedValue);
            sql = sql.Replace("*月份*", DList_month.SelectedValue);
            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

    }
}
